<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
    <link rel="stylesheet" href="//at.alicdn.com/t/c/font_4603324_hz0vtl8w1kq.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite + React + TS</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script>
  </body>
</html>
<script>
  const queryString = 'https://example.com/?name=binjie09&age=25&gender=male&age=26';
  const params = new URLSearchParams(window.location.search);
  const result = {};
for (const [key, value] of params) {
  if (result[key] === undefined) {
    // 第一次出现的键，直接赋值
    result[key] = value;
  } else {
    // 已经存在的键，转换为数组形式存储多个值
    if (!Array.isArray(result[key])) {
      result[key] = [result[key]];
    }
    result[key].push(value);
  }
}

console.log(result); // 输出 { a: ['1', '3'], b: '2' }
</script>
